﻿Imports System.Web.Helpers

Namespace SchoolClick
    Public NotInheritable Class EmailServices
        Private Shared Sub SendEmail(correo As String, Asunto As String, contenido As String, IsHTML As Boolean)
            Try
                WebMail.SmtpServer = "smtp.gmail.com"
                WebMail.SmtpPort = 587
                WebMail.EnableSsl = True
                WebMail.UserName = ConfigurationManager.AppSettings("CorreoE")
                WebMail.From = ConfigurationManager.AppSettings("CorreoE")
                WebMail.Password = ConfigurationManager.AppSettings("CorreoEPassword").ToSecureString.ToStringInseguro

                'Enviar el correo a la direccion especificado
                WebMail.Send(correo, Asunto, contenido, isBodyHtml:=IsHTML)
            Catch ex As Exception
                Throw ex
            End Try
        End Sub

        Public Shared Sub SendProfesorAccount(model As InfoProfesor, controlador As Controller)
            Try
                Dim htmlBody = controlador.ToRenderPartialView("EmailProfesorAccount", model)
                EmailServices.SendEmail(model.CorreoE, "Bienvenid@ a SchoolClick® System del Instituto Nacional de Ciudad Arce", htmlBody, True)
            Catch ex As Exception
                Throw New ApplicationException(String.Format("Ocurrió un error al intentar enviar el correo electronico al nuevo profesor. {0}", ex.Message))
            End Try
        End Sub
    End Class
End Namespace
